$(function() {
    //获取token,orderId,orderSkuId
    var token = localStorage.token;
    var orderId = parseInt(tools.queryString().orderId);
    var orderSkuId = parseInt(tools.queryString().orderSkuId);
    function loadOrderDetail(url) {
        $.ajax({
            type: "get",
            url: url,
            beforeSend: function (xhr) {
                xhr.setRequestHeader("token", token);
            },
            success: function (response) {
                if(response.data.rtnCode===200) {
                    var orderDetail = response.data.data;
                    console.log(orderDetail);
                    $(".orderDetail").html(template("orderDetail",{orderDetail:orderDetail}));
                }
                if (response.data.rtnCode === 401) {
                    var outTimeCode = response.data.rtnCode;
                    location.href = "../../index.html?outTimeCode=" + outTimeCode;
                }
            }
        });
    }
    if(orderId) {
        loadOrderDetail(domain.test + "/getorderdetail?orderId=" + orderId);
    }
    if(orderSkuId) {
        loadOrderDetail(domain.test + "/getorderdetail?orderSkuId=" + orderSkuId);
    }
    console.log(orderId);
    //取消订单
    $(".orderDetail").on("click",".cancleOrderBtn",function() {
        $.ajax({
            type: "get",
            url: domain.test + "/cancleorder",
            data: {id:orderId},
            beforeSend: function (xhr) {
                xhr.setRequestHeader("token",token);
            },
            success: function (response) {
                if(response.data.rtnCode===200) {
                    location.reload();
                }
            }
        });
    });
});